package com.alesj.tests.bool;

import java.util.HashSet;
import java.util.Set;
import java.util.Collections;
import java.util.Arrays;

import com.alesj.newsfeed.bool.Condition;
import com.alesj.newsfeed.bool.ConditionCreator;
import com.alesj.newsfeed.bool.Executor;
import com.alesj.newsfeed.bool.impl.ExecutorImpl;
import com.alesj.newsfeed.bool.impl.TokenizerImpl;

/**
 * @author <a href="mailto:ales.justin@gmail.com">Ales Justin</a>
 */
public class SqlTest {

    private static Set<String> ALL = new HashSet<String>(Arrays.asList("test", "foo", "bar", "xya", "x", "y", "t", "w"));

    public static void main(String[] args) {
        try {
            execute("!test AND !(foo or bar)");
            execute("!test or !foo");
            execute("!!test");
            execute("!test");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void execute(String query) {
        Executor<String> executor = new ExecutorImpl<String>(new TokenizerImpl<String>(new CC()));
        Set<String> set = executor.execute(query);
        System.out.println(set);
    }

    private static class CC implements ConditionCreator<String> {
        public Set<String> all() {
            return new HashSet<String>(ALL);
        }

        public Condition<String> createCondition(String condition) {
            return new TestCondition(condition);
        }
    }

    private static class TestCondition implements Condition<String> {
        private String string;

        public TestCondition(String string) {
            this.string = string;
        }

        public Set<String> execute() {
            return new HashSet<String>(Collections.singleton(string));
        }
    }
}
